package coba.mailing.query;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import coba.mailing.model.FormularioCoordinador;

public class FindFormularioCoordinadorBySolicitudId {

	public static List<FormularioCoordinador> find(Connection con, Long solicitudId) throws SQLException {

		String sql = " select * from COBA_FormularioCoordinador fc inner join COBA_FormularioGrupo fg on fc.formularioId = fg.id_ "
				+ " and fg.solicitudId = ? ";

		PreparedStatement stmt = con.prepareStatement(sql);

		stmt.setLong(1, solicitudId);

		ResultSet rs = stmt.executeQuery();

		List<FormularioCoordinador> list = new LinkedList<FormularioCoordinador>();

		while (rs.next()) {
			FormularioCoordinador obj = new FormularioCoordinador(
					rs.getLong("fc.id_"),
					rs.getString("fc.nombre"),
					rs.getString("fc.apellido"),
					rs.getString("fc.telefono"));

			list.add(obj);
		}

		rs.close();
		stmt.close();

		return list;

	}

}
